<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::SchemaStatements</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::SchemaStatements 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../../files/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements_rb.html">activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-add_column">add_column</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-change_column">change_column</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-change_column_default">change_column_default</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-change_column_null">change_column_null</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-client_min_messages">client_min_messages</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-client_min_messages-3D">client_min_messages=</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-collation">collation</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-columns">columns</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-create_database">create_database</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-create_schema">create_schema</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-ctype">ctype</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-current_database">current_database</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-current_schema">current_schema</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-drop_schema">drop_schema</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-encoding">encoding</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>I</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-index_name_length">index_name_length</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-indexes">indexes</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>P</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-primary_key">primary_key</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-rename_column">rename_column</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-rename_index">rename_index</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-rename_table">rename_table</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-schema_exists-3F">schema_exists?</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-schema_names">schema_names</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-schema_search_path">schema_search_path</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-schema_search_path-3D">schema_search_path=</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-serial_sequence">serial_sequence</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-table_exists-3F">table_exists?</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-tables">tables</a>,
              </li>
            
              
              <li>
                <a href="SchemaStatements.html#method-i-type_to_sql">type_to_sql</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-add_column">
            
              <b>add_column</b>(table_name, column_name, type, options = {})
            
            <a href="SchemaStatements.html#method-i-add_column" name="method-i-add_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Adds a new column to the named table. See <a
href="TableDefinition.html#method-i-column">ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition#column</a>
for details of the options you can use.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-add_column_source')" id="l_method-i-add_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L377" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-add_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 377</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">type</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">clear_cache!</span>
  <span class="ruby-keyword">super</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-change_column">
            
              <b>change_column</b>(table_name, column_name, type, options = {})
            
            <a href="SchemaStatements.html#method-i-change_column" name="method-i-change_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Changes the column of a table.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-change_column_source')" id="l_method-i-change_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L383" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-change_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 383</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">change_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">type</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">clear_cache!</span>
  <span class="ruby-identifier">quoted_table_name</span> = <span class="ruby-identifier">quote_table_name</span>(<span class="ruby-identifier">table_name</span>)

  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}&quot;</span>

  <span class="ruby-identifier">change_column_default</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">options</span>[<span class="ruby-value">:default</span>]) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options_include_default?</span>(<span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">change_column_null</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">options</span>[<span class="ruby-value">:null</span>], <span class="ruby-identifier">options</span>[<span class="ruby-value">:default</span>]) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:null</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-change_column_default">
            
              <b>change_column_default</b>(table_name, column_name, default)
            
            <a href="SchemaStatements.html#method-i-change_column_default" name="method-i-change_column_default" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Changes the default value of a table column.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-change_column_default_source')" id="l_method-i-change_column_default_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L394" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-change_column_default_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 394</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">change_column_default</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">default</span>)
  <span class="ruby-identifier">clear_cache!</span>
  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{quote(default)}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-change_column_null">
            
              <b>change_column_null</b>(table_name, column_name, null, default = nil)
            
            <a href="SchemaStatements.html#method-i-change_column_null" name="method-i-change_column_null" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-change_column_null_source')" id="l_method-i-change_column_null_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L399" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-change_column_null_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 399</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">change_column_null</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">null</span>, <span class="ruby-identifier">default</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">clear_cache!</span>
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">null</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>.<span class="ruby-identifier">nil?</span>
    <span class="ruby-identifier">execute</span>(<span class="ruby-node">&quot;UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL&quot;</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">execute</span>(<span class="ruby-node">&quot;ALTER TABLE #{quote_table_name(table_name)} ALTER #{quote_column_name(column_name)} #{null ? 'DROP' : 'SET'} NOT NULL&quot;</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-client_min_messages">
            
              <b>client_min_messages</b>()
            
            <a href="SchemaStatements.html#method-i-client_min_messages" name="method-i-client_min_messages" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the current client message level.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-client_min_messages_source')" id="l_method-i-client_min_messages_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L253" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-client_min_messages_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 253</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">client_min_messages</span>
  <span class="ruby-identifier">query</span>(<span class="ruby-string">'SHOW client_min_messages'</span>, <span class="ruby-string">'SCHEMA'</span>)[<span class="ruby-number">0</span>][<span class="ruby-number">0</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-client_min_messages-3D">
            
              <b>client_min_messages=</b>(level)
            
            <a href="SchemaStatements.html#method-i-client_min_messages-3D" name="method-i-client_min_messages-3D" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Set the client message level.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-client_min_messages-3D_source')" id="l_method-i-client_min_messages-3D_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L258" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-client_min_messages-3D_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 258</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">client_min_messages=</span>(<span class="ruby-identifier">level</span>)
  <span class="ruby-identifier">execute</span>(<span class="ruby-node">&quot;SET client_min_messages TO '#{level}'&quot;</span>, <span class="ruby-string">'SCHEMA'</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-collation">
            
              <b>collation</b>()
            
            <a href="SchemaStatements.html#method-i-collation" name="method-i-collation" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the current database collation.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-collation_source')" id="l_method-i-collation_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L201" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-collation_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 201</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">collation</span>
          <span class="ruby-identifier">query</span>(<span class="ruby-string">&quot;            SELECT pg_database.datcollate FROM pg_database WHERE pg_database.datname LIKE '#{current_database}'
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>)[<span class="ruby-number">0</span>][<span class="ruby-number">0</span>]
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-columns">
            
              <b>columns</b>(table_name)
            
            <a href="SchemaStatements.html#method-i-columns" name="method-i-columns" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the list of all column definitions for a table.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-columns_source')" id="l_method-i-columns_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L172" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-columns_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 172</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">columns</span>(<span class="ruby-identifier">table_name</span>)
  <span class="ruby-comment"># Limit, precision, and scale are all handled by the superclass.</span>
  <span class="ruby-identifier">column_definitions</span>(<span class="ruby-identifier">table_name</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">type</span>, <span class="ruby-identifier">default</span>, <span class="ruby-identifier">notnull</span>, <span class="ruby-identifier">oid</span>, <span class="ruby-identifier">fmod</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">oid</span> = <span class="ruby-constant">OID</span><span class="ruby-operator">::</span><span class="ruby-constant">TYPE_MAP</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">oid</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">fmod</span>.<span class="ruby-identifier">to_i</span>) {
      <span class="ruby-constant">OID</span><span class="ruby-operator">::</span><span class="ruby-constant">Identity</span>.<span class="ruby-identifier">new</span>
    }
    <span class="ruby-constant">PostgreSQLColumn</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">default</span>, <span class="ruby-identifier">oid</span>, <span class="ruby-identifier">type</span>, <span class="ruby-identifier">notnull</span> <span class="ruby-operator">==</span> <span class="ruby-string">'f'</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-create_database">
            
              <b>create_database</b>(name, options = {})
            
            <a href="SchemaStatements.html#method-i-create_database" name="method-i-create_database" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Create a new PostgreSQL database. Options include <code>:owner</code>,
<code>:template</code>, <code>:encoding</code>, <code>:collation</code>,
<code>:ctype</code>, <code>:tablespace</code>, and
<code>:connection_limit</code> (note that MySQL uses <code>:charset</code>
while PostgreSQL uses <code>:encoding</code>).</p>

<p>Example:</p>

<pre>create_database config[:database], config
create_database 'foo_development', encoding: 'unicode'</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-create_database_source')" id="l_method-i-create_database_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L56" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-create_database_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 56</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create_database</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">options</span> = { <span class="ruby-identifier">encoding</span><span class="ruby-operator">:</span> <span class="ruby-string">'utf8'</span> }.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">options</span>.<span class="ruby-identifier">symbolize_keys</span>)

  <span class="ruby-identifier">option_string</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">sum</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">key</span>
    <span class="ruby-keyword">when</span> <span class="ruby-value">:owner</span>
      <span class="ruby-node">&quot; OWNER = \&quot;#{value}\&quot;&quot;</span>
    <span class="ruby-keyword">when</span> <span class="ruby-value">:template</span>
      <span class="ruby-node">&quot; TEMPLATE = \&quot;#{value}\&quot;&quot;</span>
    <span class="ruby-keyword">when</span> <span class="ruby-value">:encoding</span>
      <span class="ruby-node">&quot; ENCODING = '#{value}'&quot;</span>
    <span class="ruby-keyword">when</span> <span class="ruby-value">:collation</span>
      <span class="ruby-node">&quot; LC_COLLATE = '#{value}'&quot;</span>
    <span class="ruby-keyword">when</span> <span class="ruby-value">:ctype</span>
      <span class="ruby-node">&quot; LC_CTYPE = '#{value}'&quot;</span>
    <span class="ruby-keyword">when</span> <span class="ruby-value">:tablespace</span>
      <span class="ruby-node">&quot; TABLESPACE = \&quot;#{value}\&quot;&quot;</span>
    <span class="ruby-keyword">when</span> <span class="ruby-value">:connection_limit</span>
      <span class="ruby-node">&quot; CONNECTION LIMIT = #{value}&quot;</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-string">&quot;&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;CREATE DATABASE #{quote_table_name(name)}#{option_string}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-create_schema">
            
              <b>create_schema</b>(schema_name)
            
            <a href="SchemaStatements.html#method-i-create_schema" name="method-i-create_schema" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Creates a schema for the given schema name.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-create_schema_source')" id="l_method-i-create_schema_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L226" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-create_schema_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 226</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create_schema</span> <span class="ruby-identifier">schema_name</span>
  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;CREATE SCHEMA #{schema_name}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-ctype">
            
              <b>ctype</b>()
            
            <a href="SchemaStatements.html#method-i-ctype" name="method-i-ctype" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the current database ctype.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-ctype_source')" id="l_method-i-ctype_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L208" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-ctype_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 208</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">ctype</span>
          <span class="ruby-identifier">query</span>(<span class="ruby-string">&quot;            SELECT pg_database.datctype FROM pg_database WHERE pg_database.datname LIKE '#{current_database}'
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>)[<span class="ruby-number">0</span>][<span class="ruby-number">0</span>]
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-current_database">
            
              <b>current_database</b>()
            
            <a href="SchemaStatements.html#method-i-current_database" name="method-i-current_database" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the current database name.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-current_database_source')" id="l_method-i-current_database_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L183" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-current_database_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 183</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">current_database</span>
  <span class="ruby-identifier">query</span>(<span class="ruby-string">'select current_database()'</span>, <span class="ruby-string">'SCHEMA'</span>)[<span class="ruby-number">0</span>][<span class="ruby-number">0</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-current_schema">
            
              <b>current_schema</b>()
            
            <a href="SchemaStatements.html#method-i-current_schema" name="method-i-current_schema" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the current schema name.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-current_schema_source')" id="l_method-i-current_schema_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L188" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-current_schema_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 188</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">current_schema</span>
  <span class="ruby-identifier">query</span>(<span class="ruby-string">'SELECT current_schema'</span>, <span class="ruby-string">'SCHEMA'</span>)[<span class="ruby-number">0</span>][<span class="ruby-number">0</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-drop_schema">
            
              <b>drop_schema</b>(schema_name)
            
            <a href="SchemaStatements.html#method-i-drop_schema" name="method-i-drop_schema" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Drops the schema for the given schema name.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-drop_schema_source')" id="l_method-i-drop_schema_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L231" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-drop_schema_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 231</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">drop_schema</span> <span class="ruby-identifier">schema_name</span>
  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;DROP SCHEMA #{schema_name} CASCADE&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-encoding">
            
              <b>encoding</b>()
            
            <a href="SchemaStatements.html#method-i-encoding" name="method-i-encoding" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the current database encoding format.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-encoding_source')" id="l_method-i-encoding_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L193" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-encoding_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 193</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">encoding</span>
          <span class="ruby-identifier">query</span>(<span class="ruby-string">&quot;            SELECT pg_encoding_to_char(pg_database.encoding) FROM pg_database
            WHERE pg_database.datname LIKE '#{current_database}'
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>)[<span class="ruby-number">0</span>][<span class="ruby-number">0</span>]
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-index_name_length">
            
              <b>index_name_length</b>()
            
            <a href="SchemaStatements.html#method-i-index_name_length" name="method-i-index_name_length" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-index_name_length_source')" id="l_method-i-index_name_length_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L427" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-index_name_length_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 427</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">index_name_length</span>
  <span class="ruby-number">63</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-indexes">
            
              <b>indexes</b>(table_name, name = nil)
            
            <a href="SchemaStatements.html#method-i-indexes" name="method-i-indexes" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an array of indexes for the given table.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-indexes_source')" id="l_method-i-indexes_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L130" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-indexes_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 130</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">indexes</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">name</span> = <span class="ruby-keyword">nil</span>)
           <span class="ruby-identifier">result</span> = <span class="ruby-identifier">query</span>(<span class="ruby-string">&quot;             SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid
             FROM pg_class t
             INNER JOIN pg_index d ON t.oid = d.indrelid
             INNER JOIN pg_class i ON d.indexrelid = i.oid
             WHERE i.relkind = 'i'
               AND d.indisprimary = 'f'
               AND t.relname = '#{table_name}'
               AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) )
            ORDER BY i.relname
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>)

          <span class="ruby-identifier">result</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span>
            <span class="ruby-identifier">index_name</span> = <span class="ruby-identifier">row</span>[<span class="ruby-number">0</span>]
            <span class="ruby-identifier">unique</span> = <span class="ruby-identifier">row</span>[<span class="ruby-number">1</span>] <span class="ruby-operator">==</span> <span class="ruby-string">'t'</span>
            <span class="ruby-identifier">indkey</span> = <span class="ruby-identifier">row</span>[<span class="ruby-number">2</span>].<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot; &quot;</span>)
            <span class="ruby-identifier">inddef</span> = <span class="ruby-identifier">row</span>[<span class="ruby-number">3</span>]
            <span class="ruby-identifier">oid</span> = <span class="ruby-identifier">row</span>[<span class="ruby-number">4</span>]

            <span class="ruby-identifier">columns</span> = <span class="ruby-constant">Hash</span>[<span class="ruby-identifier">query</span>(<span class="ruby-string">&quot;            SELECT a.attnum, a.attname
            FROM pg_attribute a
            WHERE a.attrelid = #{oid}
            AND a.attnum IN (#{indkey.join(&quot;,&quot;)})
&quot;</span>, <span class="ruby-string">&quot;SCHEMA&quot;</span>)]

            <span class="ruby-identifier">column_names</span> = <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">values_at</span>(*<span class="ruby-identifier">indkey</span>).<span class="ruby-identifier">compact</span>

            <span class="ruby-keyword">unless</span> <span class="ruby-identifier">column_names</span>.<span class="ruby-identifier">empty?</span>
              <span class="ruby-comment"># add info on sort order for columns (only desc order is explicitly specified, asc is the default)</span>
              <span class="ruby-identifier">desc_order_columns</span> = <span class="ruby-identifier">inddef</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(\w+) DESC/</span>).<span class="ruby-identifier">flatten</span>
              <span class="ruby-identifier">orders</span> = <span class="ruby-identifier">desc_order_columns</span>.<span class="ruby-identifier">any?</span> <span class="ruby-operator">?</span> <span class="ruby-constant">Hash</span>[<span class="ruby-identifier">desc_order_columns</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">order_column</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">order_column</span>, <span class="ruby-value">:desc</span>]}] <span class="ruby-operator">:</span> {}
              <span class="ruby-identifier">where</span> = <span class="ruby-identifier">inddef</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/WHERE (.+)$/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-number">0</span>]
              <span class="ruby-identifier">using</span> = <span class="ruby-identifier">inddef</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/USING (.+?) /</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-number">0</span>].<span class="ruby-identifier">to_sym</span>

              <span class="ruby-constant">IndexDefinition</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">index_name</span>, <span class="ruby-identifier">unique</span>, <span class="ruby-identifier">column_names</span>, [], <span class="ruby-identifier">orders</span>, <span class="ruby-identifier">where</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">using</span>)
            <span class="ruby-keyword">end</span>
          <span class="ruby-keyword">end</span>.<span class="ruby-identifier">compact</span>
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-primary_key">
            
              <b>primary_key</b>(table)
            
            <a href="SchemaStatements.html#method-i-primary_key" name="method-i-primary_key" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns just a table’s primary key</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-primary_key_source')" id="l_method-i-primary_key_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L345" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-primary_key_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 345</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">primary_key</span>(<span class="ruby-identifier">table</span>)
          <span class="ruby-identifier">row</span> = <span class="ruby-identifier">exec_query</span>(<span class="ruby-string">&quot;            SELECT attr.attname
            FROM pg_attribute attr
            INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1]
            WHERE cons.contype = 'p'
              AND cons.conrelid = '#{quote_table_name(table)}'::regclass
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>).<span class="ruby-identifier">rows</span>.<span class="ruby-identifier">first</span>

          <span class="ruby-identifier">row</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">first</span>
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-rename_column">
            
              <b>rename_column</b>(table_name, column_name, new_column_name)
            
            <a href="SchemaStatements.html#method-i-rename_column" name="method-i-rename_column" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Renames a column in a table.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-rename_column_source')" id="l_method-i-rename_column_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L408" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-rename_column_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 408</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">rename_column</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">new_column_name</span>)
  <span class="ruby-identifier">clear_cache!</span>
  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;ALTER TABLE #{quote_table_name(table_name)} RENAME COLUMN #{quote_column_name(column_name)} TO #{quote_column_name(new_column_name)}&quot;</span>
  <span class="ruby-identifier">rename_column_indexes</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">new_column_name</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-rename_index">
            
              <b>rename_index</b>(table_name, old_name, new_name)
            
            <a href="SchemaStatements.html#method-i-rename_index" name="method-i-rename_index" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-rename_index_source')" id="l_method-i-rename_index_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L423" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-rename_index_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 423</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">rename_index</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">old_name</span>, <span class="ruby-identifier">new_name</span>)
  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;ALTER INDEX #{quote_column_name(old_name)} RENAME TO #{quote_table_name(new_name)}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-rename_table">
            
              <b>rename_table</b>(table_name, new_name)
            
            <a href="SchemaStatements.html#method-i-rename_table" name="method-i-rename_table" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Renames a table. Also renames a table’s primary key sequence if the
sequence name matches the Active Record default.</p>

<p>Example:</p>

<pre>rename_table('octopuses', 'octopi')</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-rename_table_source')" id="l_method-i-rename_table_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L363" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-rename_table_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 363</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">rename_table</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">new_name</span>)
  <span class="ruby-identifier">clear_cache!</span>
  <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;ALTER TABLE #{quote_table_name(table_name)} RENAME TO #{quote_table_name(new_name)}&quot;</span>
  <span class="ruby-identifier">pk</span>, <span class="ruby-identifier">seq</span> = <span class="ruby-identifier">pk_and_sequence_for</span>(<span class="ruby-identifier">new_name</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">seq</span> <span class="ruby-operator">==</span> <span class="ruby-node">&quot;#{table_name}_#{pk}_seq&quot;</span>
    <span class="ruby-identifier">new_seq</span> = <span class="ruby-node">&quot;#{new_name}_#{pk}_seq&quot;</span>
    <span class="ruby-identifier">execute</span> <span class="ruby-node">&quot;ALTER TABLE #{quote_table_name(seq)} RENAME TO #{quote_table_name(new_seq)}&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">rename_table_indexes</span>(<span class="ruby-identifier">table_name</span>, <span class="ruby-identifier">new_name</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-schema_exists-3F">
            
              <b>schema_exists?</b>(name)
            
            <a href="SchemaStatements.html#method-i-schema_exists-3F" name="method-i-schema_exists-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns true if schema exists.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-schema_exists-3F_source')" id="l_method-i-schema_exists-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L121" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-schema_exists-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 121</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">schema_exists?</span>(<span class="ruby-identifier">name</span>)
          <span class="ruby-identifier">exec_query</span>(<span class="ruby-string">&quot;            SELECT COUNT(*)
            FROM pg_namespace
            WHERE nspname = '#{name}'
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>).<span class="ruby-identifier">rows</span>.<span class="ruby-identifier">first</span>[<span class="ruby-number">0</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-number">0</span>
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-schema_names">
            
              <b>schema_names</b>()
            
            <a href="SchemaStatements.html#method-i-schema_names" name="method-i-schema_names" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an array of schema names.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-schema_names_source')" id="l_method-i-schema_names_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L215" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-schema_names_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 215</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">schema_names</span>
          <span class="ruby-identifier">query</span>(<span class="ruby-string">&quot;            SELECT nspname
              FROM pg_namespace
             WHERE nspname !~ '^pg_.*'
               AND nspname NOT IN ('information_schema')
             ORDER by nspname;
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>).<span class="ruby-identifier">flatten</span>
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-schema_search_path">
            
              <b>schema_search_path</b>()
            
            <a href="SchemaStatements.html#method-i-schema_search_path" name="method-i-schema_search_path" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the active schema search path.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-schema_search_path_source')" id="l_method-i-schema_search_path_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L248" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-schema_search_path_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 248</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">schema_search_path</span>
  <span class="ruby-ivar">@schema_search_path</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">query</span>(<span class="ruby-string">'SHOW search_path'</span>, <span class="ruby-string">'SCHEMA'</span>)[<span class="ruby-number">0</span>][<span class="ruby-number">0</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-schema_search_path-3D">
            
              <b>schema_search_path=</b>(schema_csv)
            
            <a href="SchemaStatements.html#method-i-schema_search_path-3D" name="method-i-schema_search_path-3D" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Sets the schema search path to a string of comma-separated schema names.
Names beginning with $ have to be quoted (e.g. $user =&gt; ‘$user’). See:
<a
href="http://www.postgresql.org/docs/current/static/ddl-schemas.html">www.postgresql.org/docs/current/static/ddl-schemas.html</a></p>

<p>This should be not be called manually but set in database.yml.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-schema_search_path-3D_source')" id="l_method-i-schema_search_path-3D_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L240" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-schema_search_path-3D_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 240</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">schema_search_path=</span>(<span class="ruby-identifier">schema_csv</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">schema_csv</span>
    <span class="ruby-identifier">execute</span>(<span class="ruby-node">&quot;SET search_path TO #{schema_csv}&quot;</span>, <span class="ruby-string">'SCHEMA'</span>)
    <span class="ruby-ivar">@schema_search_path</span> = <span class="ruby-identifier">schema_csv</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-serial_sequence">
            
              <b>serial_sequence</b>(table, column)
            
            <a href="SchemaStatements.html#method-i-serial_sequence" name="method-i-serial_sequence" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-serial_sequence_source')" id="l_method-i-serial_sequence_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L271" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-serial_sequence_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 271</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">serial_sequence</span>(<span class="ruby-identifier">table</span>, <span class="ruby-identifier">column</span>)
          <span class="ruby-identifier">result</span> = <span class="ruby-identifier">exec_query</span>(<span class="ruby-string">&quot;            SELECT pg_get_serial_sequence('#{table}', '#{column}')
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>)
          <span class="ruby-identifier">result</span>.<span class="ruby-identifier">rows</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">first</span>
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-table_exists-3F">
            
              <b>table_exists?</b>(name)
            
            <a href="SchemaStatements.html#method-i-table_exists-3F" name="method-i-table_exists-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns true if table exists. If the schema is not specified as part of
<code>name</code> then it will only find tables within the current schema
search path (regardless of permissions to access tables in other schemas)</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-table_exists-3F_source')" id="l_method-i-table_exists-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L103" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-table_exists-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 103</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">table_exists?</span>(<span class="ruby-identifier">name</span>)
          <span class="ruby-identifier">schema</span>, <span class="ruby-identifier">table</span> = <span class="ruby-constant">Utils</span>.<span class="ruby-identifier">extract_schema_and_table</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>)
          <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">table</span>

          <span class="ruby-identifier">binds</span> = [[<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">table</span>]]
          <span class="ruby-identifier">binds</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">schema</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">schema</span>

          <span class="ruby-identifier">exec_query</span>(<span class="ruby-string">&quot;              SELECT COUNT(*)
              FROM pg_class c
              LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
              WHERE c.relkind in ('v','r')
              AND c.relname = '#{table.gsub(/(^&quot;|&quot;$)/,'')}'
              AND n.nspname = #{schema ? &quot;'#{schema}'&quot; : 'ANY (current_schemas(false))'}
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>).<span class="ruby-identifier">rows</span>.<span class="ruby-identifier">first</span>[<span class="ruby-number">0</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-number">0</span>
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-tables">
            
              <b>tables</b>(name = nil)
            
            <a href="SchemaStatements.html#method-i-tables" name="method-i-tables" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns the list of all tables in the schema search path or a specified
schema.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-tables_source')" id="l_method-i-tables_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L92" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-tables_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 92</span>
        <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">tables</span>(<span class="ruby-identifier">name</span> = <span class="ruby-keyword">nil</span>)
          <span class="ruby-identifier">query</span>(<span class="ruby-string">&quot;            SELECT tablename
            FROM pg_tables
            WHERE schemaname = ANY (current_schemas(false))
&quot;</span>, <span class="ruby-string">'SCHEMA'</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">row</span><span class="ruby-operator">|</span> <span class="ruby-identifier">row</span>[<span class="ruby-number">0</span>] }
        <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-type_to_sql">
            
              <b>type_to_sql</b>(type, limit = nil, precision = nil, scale = nil)
            
            <a href="SchemaStatements.html#method-i-type_to_sql" name="method-i-type_to_sql" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Maps logical <a href="../../../Rails.html">Rails</a> types to
PostgreSQL-specific data types.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-type_to_sql_source')" id="l_method-i-type_to_sql_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/7860bf11d862a6eb1bd9ada85bcd97f17a2cb536/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L432" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-type_to_sql_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 432</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">type_to_sql</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">limit</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">precision</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">scale</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">type</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'binary'</span>
    <span class="ruby-comment"># PostgreSQL doesn't support limits on binary (bytea) columns.</span>
    <span class="ruby-comment"># The hard limit is 1Gb, because of a 32-bit size field, and TOAST.</span>
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">limit</span>
    <span class="ruby-keyword">when</span> <span class="ruby-keyword">nil</span>, <span class="ruby-number">0</span><span class="ruby-operator">..</span><span class="ruby-number">0x3fffffff</span>; <span class="ruby-keyword">super</span>(<span class="ruby-identifier">type</span>)
    <span class="ruby-keyword">else</span> <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ActiveRecordError</span>, <span class="ruby-node">&quot;No binary type has byte size #{limit}.&quot;</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'text'</span>
    <span class="ruby-comment"># PostgreSQL doesn't support limits on text columns.</span>
    <span class="ruby-comment"># The hard limit is 1Gb, according to section 8.3 in the manual.</span>
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">limit</span>
    <span class="ruby-keyword">when</span> <span class="ruby-keyword">nil</span>, <span class="ruby-number">0</span><span class="ruby-operator">..</span><span class="ruby-number">0x3fffffff</span>; <span class="ruby-keyword">super</span>(<span class="ruby-identifier">type</span>)
    <span class="ruby-keyword">else</span> <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ActiveRecordError</span>, <span class="ruby-string">&quot;The limit on text can be at most 1GB - 1byte.&quot;</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'integer'</span>
    <span class="ruby-keyword">return</span> <span class="ruby-string">'integer'</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">limit</span>

    <span class="ruby-keyword">case</span> <span class="ruby-identifier">limit</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">1</span>, <span class="ruby-number">2</span>; <span class="ruby-string">'smallint'</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">3</span>, <span class="ruby-number">4</span>; <span class="ruby-string">'integer'</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">5</span><span class="ruby-operator">..</span><span class="ruby-number">8</span>; <span class="ruby-string">'bigint'</span>
      <span class="ruby-keyword">else</span> <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ActiveRecordError</span>, <span class="ruby-node">&quot;No integer type has byte size #{limit}. Use a numeric with precision 0 instead.&quot;</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">'datetime'</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">super</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">precision</span>

    <span class="ruby-keyword">case</span> <span class="ruby-identifier">precision</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">0</span><span class="ruby-operator">..</span><span class="ruby-number">6</span>; <span class="ruby-node">&quot;timestamp(#{precision})&quot;</span>
      <span class="ruby-keyword">else</span> <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ActiveRecordError</span>, <span class="ruby-node">&quot;No timestamp type has precision of #{precision}. The allowed range of precision is from 0 to 6&quot;</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">super</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    